#ifndef __MOTORCTRL__
#define __MOTORCTRL__
#include "includes.h"
#define MAXCTRL	(int)(PERIOD_CNT*0.8)
#define MINCTRL	(int)(PERIOD_CNT*0.3)

#define MAXSPEED	(int)(PERIOD_CNT*0.64)
#define MINSPEED	(int)(PERIOD_CNT*0.4)
#define IDLESPEED   (int)(PERIOD_CNT*0.4) 
#define STOPSPEED   (int)(PERIOD_CNT*0.3)
#define NORMALSPEED   (int)(PERIOD_CNT*0.55)
//#define CENTRAL		 PERIOD_CNT*0.5
#define PROPOTIONAL		5
#define INTEGRAL			3
#define DIFFERENTIAL	1

#define FULL	1
#define IDLE	2
#define NORMAL	3
#define STOP	4

#define MOTORF		1	 //PB6
#define MOTORB		3	 //PB8
#define MOTORL		2	 //PB7
#define MOTORR		4	 //PB9

typedef struct
{
 	s16 Phi;
	s16 Theta;
	s16 Psi;
	s16 height;

}ctrlstatus_t;
typedef struct
{
 	s8 p;
	s8 i;
	s8 d;
	s8 sum;
	s8 lerror;
	s8 perror;
}pid_para_t;
extern ctrlstatus_t CtrlStatus;
void MotorCalibrate(u8 cmd);
void AltitudeCtrl(void);
void MotorCtrlInit(void);
void AdjustDuty(s16 CCR_Value,u8 Channel);
s8 GetCurDuty(u8 Channel);
void StartMotor(u8 speed);
void SetAltitude(s8 phi,s8 theta);
void SetHeight(u8 height);
void StartCalli(u8 mode);
#endif
